using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using A = Atalasoft.Imaging;

namespace Tiffer {

	////////////////////////////////////////////////////////////////////////////////////////////////////
	/// <summary>	Process. </summary>
	///
	/// <remarks>	Dimon, 12/21/2010. </remarks>
	////////////////////////////////////////////////////////////////////////////////////////////////////

	public class Process {

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Determines the median of the given parameters. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		///
		/// <param name="path">	Full pathname of the file. </param>
		///
		/// <returns>	The median value. </returns>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		public static string Median(string path) {
			Bitmap pic = new Bitmap(path);
			Atalasoft.Imaging.Workspace ws = new Atalasoft.Imaging.Workspace();
			ws.Open(path);
			Atalasoft.Imaging.Workspace wsOut = new Atalasoft.Imaging.Workspace();
			foreach (Atalasoft.Imaging.AtalaImage image in ws.Images) {
				Atalasoft.Imaging.ImageProcessing.ImageCommand cmd = new Atalasoft.Imaging.ImageProcessing.Filters.MeanCommand(Atalasoft.Imaging.ImageProcessing.Filters.MeanFilterType.YP, 5);
				//Atalasoft.Imaging.ImageProcessing.ImageCommand cmd =
					//new Atalasoft.Imaging.ImageProcessing.Document.ResampleDocumentCommand(new Rectangle(new Point(0,0),image.Size),image.Size, Atalasoft.Imaging.ImageProcessing.Document.ResampleDocumentMethod.AreaAverage);
				A.AtalaImage imageOut = cmd.ApplyToImage(image);
				cmd = new A.ImageProcessing.Filters.ThresholdCommand(100, 0);
				cmd.ApplyToImage(imageOut);
				wsOut.Images.Add(imageOut);
			}
            string pathOut = Dimok.FileManager.GetSureFileName(path, "00");
			wsOut.Save(pathOut, new Atalasoft.Imaging.Codec.TiffEncoder(Atalasoft.Imaging.Codec.TiffCompression.NoCompression));
            return pathOut;
		}
	}
}
